package me.hyman.testcustomview.viewDragHelper.drawer;

import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import me.hyman.testcustomview.R;

public class LeftDrawerActivity extends AppCompatActivity {

    private LeftDrawerLayout leftDrawerLayout;
    private LeftMenuFragment leftMenuFragment;
    private TextView txtContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_left_drawer);

        leftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.lyt_drawer);
        txtContent = (TextView) findViewById(R.id.txt_content);

        FragmentManager fm = getSupportFragmentManager();
        leftMenuFragment = (LeftMenuFragment) fm.findFragmentById(R.id.lyt_container_menu);

        if(leftMenuFragment == null) {
            leftMenuFragment = new LeftMenuFragment();
            fm.beginTransaction().add(R.id.lyt_container_menu, leftMenuFragment).commit();
        }

        leftMenuFragment.setOnMenuItemClickedListener(new LeftMenuFragment.OnMenuItemClickedListener() {
            @Override
            public void onMenuItemClicked(String text) {
                txtContent.setText(text);
                leftDrawerLayout.closeDrawer();
            }
        });

    }
}
